package com.ljh.aop.proxy;

import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * @author: Themberfue
 * @date: 2025/3/27 12:40
 * @description:
 */
public class CGlibMethodInterceptor implements MethodInterceptor {
    // ! 被代理对象，目标对象
    private Object target;

    public CGlibMethodInterceptor(Object target) {
        this.target = target;
    }

    @Override
    public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
        System.out.println("开始代理");
        Object invoke = method.invoke(target, args);
        System.out.println("结束代理");
        return invoke;
    }
}
